package com.ruoyi.car.controller.parts;

import java.util.List;

import com.car.pojo.TbPartBatteryPack;
import com.ruoyi.car.service.parts.ITbPartBatteryPackService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆修改记录Controller
 *
 * @author 敬乾超
 * @date 2020-06-24
 */
@Controller
@RequestMapping("/part/batterypack")
public class TbPartBatteryPackController extends BaseController
{
    private String prefix = "part/pack";

    @Autowired
    private ITbPartBatteryPackService tbPartBatteryPackService;

    @RequiresPermissions("part:pack:view")
    @GetMapping()
    public String carUpdateRecord()
    {
        return prefix + "/pack";
    }

    @RequiresPermissions("part:pack:view")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo findAll(TbPartBatteryPack tbPartBatteryPack)
    {
        startPage();
        List<TbPartBatteryPack> all = tbPartBatteryPackService.findAll(tbPartBatteryPack);
        return getDataTable(all);
    }
    /**
     * 导出
     */
    @RequiresPermissions("part:pack:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbPartBatteryPack tbPartBatteryPack)
    {
        List<TbPartBatteryPack> list = tbPartBatteryPackService.findAll(tbPartBatteryPack);
        ExcelUtil<TbPartBatteryPack> util = new ExcelUtil<TbPartBatteryPack>(TbPartBatteryPack.class);
        return util.exportExcel(list, "pack");
    }

    /**
     * 新增
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("part:pack:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbPartBatteryPack tbPartBatteryPack)
    {
        System.out.println(tbPartBatteryPack);
        return toAjax(tbPartBatteryPackService.insertTbPartBatteryPack(tbPartBatteryPack));
    }

    /**
     * 修改
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbPartBatteryPack tbPartBatteryPack = tbPartBatteryPackService.selectTbPartBatteryPackById(id);
        mmap.put("tbPartBatteryPack", tbPartBatteryPack);
        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    @RequiresPermissions("part:pack:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbPartBatteryPack tbPartBatteryPack)
    {
        return toAjax(tbPartBatteryPackService.updateTbPartBatteryPack(tbPartBatteryPack));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("part:pack:remove")
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbPartBatteryPackService.deleteTbPartBatteryPackByIds(ids));
    }

}
